﻿/*****************************************************************************  

 Version: 0.1
 Website: http://www.visuagile.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate;
using Spring.Data.NHibernate.Support;

using VisualAgile.IDAL;
using VisualAgile.Model;
using Spring.Data.NHibernate;
using NHibernate.Engine;

namespace VisualAgile.DAL
{
    public class StoryDao : BaseDao<Story>, IStoryDao
    {
        protected override HibernateTemplate getBaseDAO()
        {
            return HibernateTemplate;
        }

        public IList FindByFeature(string FeatureId)
        {
            return HibernateTemplate.Find("from Story where FeatureID = ?", FeatureId);            
        }

        public IList FindByIteration(string IterationId)
        {
            return HibernateTemplate.Find("from Story where IterationID = ?", IterationId);            
        }

        public IList FindByProject(Guid ProjectID)
        {
            IQuery query = Session.CreateQuery("from Story S,Iteration I, Release R, Project P where S.IterationID = I.IterationID and I.ReleaseID = R.ReleaseID and R.ProjectID = P.ID and P.ID='" + ProjectID.ToString() + "'");

            IList items = query.List();
            IList stories = new List<Story>();

            foreach (object[] item in items)
            {                                       
                Story story = item[0] as Story;
                if (story != null)
                    stories.Add(story);
            }

            return stories;                       
        }
    }
}